package cn.tedu._05mvcboot02.commen.exception;

import cn.tedu._05mvcboot02.commen.response.JsonResult;
import cn.tedu._05mvcboot02.commen.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public JsonResult doHandleIllegalArgumentException(IllegalArgumentException ex){
        log.error("ex = " + ex.getMessage());
        return new JsonResult(StatusCode.OPERATION_FAILED,ex.getMessage());
    }
    @ExceptionHandler
    public JsonResult doHandleThrowableException(Throwable ex){
        log.error("ex = " + ex.getMessage());
        return new JsonResult(StatusCode.THROWABLE_ERROR,ex.getMessage());
    }
}
